package com.daiziru.template;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.daiziru.common.templates.DirectiveHandler;
import com.daiziru.common.templates.TemplateDirective;
import com.daiziru.service.MPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 置顶贴子展示自定义标签
 */
@Component
public class PostsTemplate extends TemplateDirective {

    @Autowired
    MPostService postService;

    @Override
    public String getName() {
        return "posts";
    }

    @Override
    public void execute(DirectiveHandler handler) throws Exception {

        Integer level = handler.getInteger("level"); //置顶数字等级
        Integer currentPage = handler.getInteger("pn", 1);
        Integer size = handler.getInteger("size", 5);
        Long categoryId = handler.getLong("categoryId");

        IPage page = postService.selectByPage(new Page(currentPage, size), categoryId, null, level, null, "created");

        //看TemplateDirective
        handler.put(RESULTS, page).render();
    }
}
